package com.niit.onlinemusic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.niit.onlinemusic.common.R;
import com.niit.onlinemusic.mapper.SongMapper;
import com.niit.onlinemusic.model.domain.Song;
import com.niit.onlinemusic.service.SongService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 歌曲业务层实现类
 *
 * @author zuwei522
 * @since 2025/9/19 08:30
 */
@Service
public class SongServiceImpl extends ServiceImpl<SongMapper, Song> implements SongService {

    private final SongMapper songMapper;

    public SongServiceImpl(SongMapper songMapper) {
        this.songMapper = songMapper;
    }

    @Override
    public R getSongsBySingerId(int singerId) {
        // 根据歌手ID查询歌曲
        QueryWrapper<Song> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("singer_id", singerId);
        List<Song> songList = songMapper.selectList(queryWrapper);
        return R.success("查询歌曲成功", songList);
    }

    @Override
    public R searchSongsByName(String name) {
        QueryWrapper<Song> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name", name);
        List<Song> songList = songMapper.selectList(queryWrapper);
        return R.success("查询歌曲成功", songList);
    }

}
